#include "widget.h"
#include "ui_widget.h"
#include<QIcon>
#include<QPixmap>
#include<QPalette>
#include<QDebug>
#include<QMediaPlayer>
#include<QMediaPlaylist>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowMinMaxButtonsHint|Qt::WindowSystemMenuHint);  //设置无菜单栏
    QPixmap pixmap(":/image/colorChange.jpg");
    QPalette palette=this->palette();
    palette.setBrush(QPalette::Background,QBrush(pixmap));
    this->setPalette(palette);

    player=new QMediaPlayer;
    playerlist=new QMediaPlaylist;

    ui->soundslider->hide();   //隐藏音量滑条
    ui->soundslider->setValue(20);  //初始化音量条位置
    QFile fileSlider1(":/qss/slider2.qss");   //进度条
    fileSlider1.open((QFile::ReadOnly));
    ui->soundslider->setStyleSheet(fileSlider1.readAll());

    ui->musicslider->setValue(20);
    QFile fileSlider2(":/qss/slider3.qss");
    fileSlider2.open((QFile::ReadOnly));
    ui->musicslider->setStyleSheet(fileSlider2.readAll());

    ui->btndestroy->setIcon(QIcon(":/image/XX.png"));
    ui->btnmin->setIcon(QIcon(":/image/MIN.png"));
    ui->btndestroy->setStyleSheet("QPushButton{border:none;color:rgb(255, 255, 255);}"
                                         "QPushButton:hover{background-color: #FF0000;border:none;color:rgb(255, 255, 255);}");
    ui->btnmin->setStyleSheet( "QPushButton{border:none;color:rgb(255, 255, 255);}"
                                           "QPushButton:hover{background-color: #bdddf8;border:none;color:rgb(255, 255, 255);}");

    player->setVolume(20);  //初始化音量
    playerlist->setPlaybackMode(QMediaPlaylist::Loop);
    player->setMedia(QUrl::fromLocalFile("D:/Qt/Setting/Setting/image/周杰伦 - 晴天.mp3"));
    player->play();
    ui->pushButton_music->setIcon(QIcon(":/image/void2.png"));
    ui->resumebtn->setIcon(QIcon(":/image/go.png"));
    ui->resumebtn->setStyleSheet("QPushButton{border:none;color:rgb(255, 255, 255);}");
    ui->restartbtn->setStyleSheet("QPushButton{border:none;color:rgb(255, 255, 255);}");
    ui->pushButton_music->setToolTip(tr("音乐"));
    ui->pushButton_sound->setToolTip(tr("音效"));
    ui->exitbtn->setStyleSheet("QPushButton{border:none;color:rgb(255, 255, 255);}"
                               "border:none;color:rgb(255, 255, 255);}");
    ui->btnbackground->setStyleSheet( "QPushButton{border:none;color:rgb(255, 255, 255);}"
                                      "QPushButton:hover{background-color: #bdddf8 ;border:none;color:rgb(255, 255, 255);}");
    ui->btnbackground->setIcon(QIcon(":/image/XX.png"));
    ui->btnbackground->setToolTip(tr("更换背景"));
    connect(ui->btnbackground,&QPushButton::clicked,this,&Widget::btnbackgroundclicked);
    connect(ui->soundslider,&QSlider::valueChanged,this,&Widget::setSound);  //更新音量
    //connect(ui->btnbackground,&QPushButton::clicked,this,&Widget::PhotoChange);

}

Widget::~Widget()
{
    delete ui;
}
void Widget::setSound()  //设置音量
{
    player->setVolume(ui->soundslider->value());
}
void Widget::on_resumebtn_clicked()
{ Dialog1 d;
    d.exec();

}

void Widget::on_pushButton_sound_clicked()
{
 if(!soundPressed){
     ui->soundslider->show();
     soundPressed=true;
 }
 else{
     ui->soundslider->hide();
     soundPressed=false;
 }
}

void Widget::on_pushButton_music_clicked()
{

}

void Widget::on_exitbtn_clicked()
{
    this->close();
}//多个页面一起关闭



void Widget::btnbackgroundclicked()
{
    QString ThemePath;  //主题背景路径

    if(ThemeNum==1)
    {
        ThemePath=":/image/01.jpg";   //主题图片
        ThemeNum=2;
    }
    else if(ThemeNum==2)
    {
        ThemePath=":/image/02.jpg";
        ThemeNum=3;
    }
    else if(ThemeNum==3)
    {
        ThemePath=":/image/03.jpg";
        ThemeNum=4;
    }
    else if(ThemeNum==4)
    {
        ThemePath="::/image/04.jpg";
        ThemeNum=5;
    }else if(ThemeNum==5)
    {
        ThemePath="::/image/05.jpg";
        ThemeNum=6;
    }
    else if(ThemeNum==6)
    {
        ThemePath="::/image/06.jpg";
        ThemeNum=1;
    }
    QPixmap pixmap(ThemePath);
    QPalette palette=this->palette();
    palette.setBrush(QPalette::Background,QBrush(pixmap));
    this->setPalette(palette);
}
